package com.mcxx.modules.common.controller;

import com.alibaba.fastjson.JSON;
import com.mcxx.modules.common.service.CommonService;
import com.mcxx.service.DefaultRestService;
import com.yinhai.ta404.core.context.TaUser;
import com.yinhai.ta404.core.restservice.annotation.RestService;
import com.yinhai.ta404.core.security.vo.UserAccountVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;

import java.util.HashMap;
import java.util.Map;


@Slf4j
@Validated
@Api("公共信息")
@RestService({"common/v2"})
public class CommonController extends DefaultRestService {
    @Autowired
    private CommonService commonService;

    @PostMapping("getUserInfo")
    @ApiOperation("获取用户信息")
    public void getUserInfo(String userId){
        log.info("获取用户信息，参数是：{}", JSON.toJSONString(userId));
        UserAccountVo accountVo = getCurUserAccount();
        TaUser taUser = commonService.getUserInfo(userId, accountVo.getOrgId());
        Map<String, String> map = new HashMap<String, String>();
        map.put("loginId", taUser.getLoginId());
        map.put("name", taUser.getName());
        setData(map);
        log.info("获取用户信息，结果是：{}", map.toString());
    }
}
